package main

import (
	"fmt"
	"github.com/davyxu/cellnet"
	"github.com/davyxu/cellnet/peer"
	_ "github.com/davyxu/cellnet/peer/tcp" // 注册TCP Peer
	"github.com/davyxu/cellnet/proc"
	_ "github.com/davyxu/cellnet/proc/tcp" // 注册TCP Processor
	"net"
)

func main() {
	queue := cellnet.NewEventQueue()
	p := peer.NewGenericPeer("tcp.Acceptor", "LoginServer", "0.0.0.0:8484", queue)

	proc.BindProcessorHandler(p, "tcp.ltv", func(ev cellnet.Event) {
		msg := ev.Message()
		switch msg.(type) {
		case *cellnet.SessionAccepted:
			fmt.Println("The Session Connected", ev.Session().Raw().(net.Conn).RemoteAddr())
		}
	})

	p.Start()
	queue.StartLoop()
	queue.Wait()

}
